<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="at.jku.ce.brokerplatform.*"%>

<%
	
	String user = request.getParameter("user");
	boolean isRegistered = false;
	for (User u : Users.getAllUsers()) {
		if (u.getUsername().equals(user)) {
			isRegistered = true;
			System.out.println("User existiert bereits");
		}
	}
	
	if (isRegistered) {
		RequestDispatcher rd = getServletContext().getRequestDispatcher("/register.jsp");
        out.println("<font color=red>Benutzername existiert bereits. Bitte einen anderen versuchen.</font>");
        rd.include(request, response);
	} else {
		Users.addUser(new User(request.getParameter("user"), request.getParameter("pwd"), request.getParameter("iban"), request.getParameter("bic")));
		System.out.println("neuen User angelegt");

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
	body {
		margin: 0;
		padding: 0; 
		background-image: url('boerse_grey2.jpg');
		background-attachment: fixed;
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}
</style>
<title>Register Success</title>

</head>

<body>	
	<h1>Erfolgreich registriert</h1>
	
	Um forzufahren, melden Sie sich bitte mit Ihren Logindaten an. <br /><br />
	
	<form action="Login" method="post" accept-charset="ISO-8859-1">
	Benutzername:<input name="user" type="text" size="20" maxlength="30"><br />
	Passwort:<input name="pwd" type="password" size="20" maxlength="30"><br />
	<input type="submit" value="Anmelden">
	</form><br /><br />
	
	<%
	}
	%>

</body>

</html>